<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
            <el-form-item label="角色名称" prop="roleName">
                <el-input v-model="ruleForm.roleName"></el-input>
            </el-form-item>
            <el-form-item label="英文名称" prop="enName">
                <el-input v-model="ruleForm.enName"></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {insertRole}from '@/api/roleApi'
    export default {
        data() {
            return {
                ruleForm: {
                    roleName: '',
                    enName: '',
                },
                rules: {
                    roleName: [
                        { required: true, message: '角色名称不可为空', trigger: 'blur' },
                    ],
                }
            };
        },
        methods: {
            //提交
            submit () {
                return new Promise((resolve, reject) => {
                    this.$refs['form'].validate((valid) => {
                        if (valid) {
                            insertRole(this.ruleForm).then(res => {
                                resolve(res.data)
                            }).catch(e => {
                                reject(e)
                                this.$message.error({
                                    message: '抱歉，操作角色遇到异常，请重试或联系管理员处理'
                                })
                            })
                        } else {
                            this.$message.error('业务校验未通过')
                            reject(new Error('业务校验失败'))
                        }
                    })
                })
            }
        }
    }
</script>

<style scoped>

</style>
